Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace JPC.Medialibrary.DAL
	''' <summary>
	''' Strongly-typed collection for the Genre class.
	''' </summary>
	<Serializable> _
	Public Partial Class GenreCollection 
	Inherits ActiveList(Of Genre, GenreCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the Genres table.
	''' </summary>
	<Serializable> _
	Public Partial Class Genre 
	Inherits ActiveRecord(Of Genre)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
        
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		
        
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("Genres", TableType.Table, DataService.GetInstance("Medialibrary"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarGenreId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarGenreId.ColumnName = "GenreId"
                colvarGenreId.DataType = DbType.Int32
                colvarGenreId.MaxLength = 0
                colvarGenreId.AutoIncrement = false
                colvarGenreId.IsNullable = false
                colvarGenreId.IsPrimaryKey = true
                colvarGenreId.IsForeignKey = false
                colvarGenreId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarGenreId)
                
                Dim colvarNombre As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarNombre.ColumnName = "Nombre"
                colvarNombre.DataType = DbType.String
                colvarNombre.MaxLength = 20
                colvarNombre.AutoIncrement = false
                colvarNombre.IsNullable = true
                colvarNombre.IsPrimaryKey = false
                colvarNombre.IsForeignKey = false
                colvarNombre.IsReadOnly = false
                
                
                schema.Columns.Add(colvarNombre)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("Medialibrary").AddSchema("Genres",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("GenreId")> _
        Public Property GenreId As Integer 
			Get
				Return GetColumnValue(Of Integer)(Columns.GenreId)
			End Get
		    
			Set
				SetColumnValue(Columns.GenreId, Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Nombre")> _
        Public Property Nombre As String 
			Get
				Return GetColumnValue(Of String)(Columns.Nombre)
			End Get
		    
			Set
				SetColumnValue(Columns.Nombre, Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
		
		
		
		
		
		
		
	    'no foreign key tables defined (0)
	    
		
		
	    'no ManyToMany tables defined (0)
	    
		
        
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varGenreId As Integer,ByVal varNombre As String)
			Dim item As Genre = New Genre()
			
            item.GenreId = varGenreId
            
            item.Nombre = varNombre
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varGenreId As Integer,ByVal varNombre As String)
			Dim item As Genre = New Genre()
		    
                item.GenreId = varGenreId
				
                item.Nombre = varNombre
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		
		
		#Region "Typed Columns"
        
        
        Public Shared ReadOnly Property GenreIdColumn() As TableSchema.TableColumn
            Get
                Return Schema.Columns(0)
            End Get
        End Property
        
        
        Public Shared ReadOnly Property NombreColumn() As TableSchema.TableColumn
            Get
                Return Schema.Columns(1)
            End Get
        End Property
        
        
        #End Region
		
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared GenreId As String = "GenreId"
            
            Public Shared Nombre As String = "Nombre"
            
		End Structure
		#End Region
		
				
		#Region "Update PK Collections"
		
        #End Region
        
        #Region "Deep Save"
		
        #End Region
        
	End Class
End Namespace
